﻿using System;
using System.Collections.Generic;
using System.Web;

namespace IntelligentCMS
{
    /// <summary>
    /// Provides load balancing for larger sites.
    /// </summary>
    public class CMSLoadBalancing
    {
        public CMSLoadBalancing()
        {
            Load();
        }

        private List<string> servers = new List<string>();

        public List<string> Servers
        {
            get
            {
                return servers;
            }

        }

        private void Load()
        {
            /*
            CMSDbDataLayer newDataLayer = new CMSDbDataLayer(string.Empty, CMSDbDataHelper.Microsoft);
            newDataLayer.AddQuery("SELECT [IPAddress] FROM CMS_LoadBalancing");
            newDataLayer.NonQuery = true;
            newDataLayer.Execute();

            for (int i = 0; i < newDataLayer.Data.Rows.Count; i++)
            {
                servers.Add(newDataLayer.Data.Rows[i].ItemArray[0].ToString());
            }
            */

        }


        public void Add(string address)
        {
            servers.Add(address);

        }

        public void Delete(string address)
        {

            int index = -1;
            for (int i = 0; i < servers.Count; i++)
            {
                if (servers[i] == address)
                {
                    index = i;

                }

            }

            if (index > -1)
            {
                
                servers.RemoveAt(index);
            }

        }
    }
}
